#include<iostream>
#include <string>
#include <vector>
using namespace std;
class Solution {
public:
    int romanToInt(string str) {
        int a[] = { 1000,900,500,400,100,90,50,40,10,9,5,4,1 };
        string s[] = { "M","CM","D" ,"CD","C","XC","L","XL","X","IX","V","IV","I" };
        int ans = 0, pi = 0;
        bool pd;
        for (int i = 0; i < 13; i++)
        {
            pd = 1;
            for (int j = 0; j < s[i].length(); j++)
            {
                if (str[pi + j] != s[i][j])
                {
                    pd = 0;
                    break;
                }
            }
            if (pd)
            {
                ans += a[i];
                pi += s[i].length();
                i--;
            }
        }
        return ans;
    }
};
int main()
{
    Solution sol;
    cout << sol.romanToInt("MCMXCIV") << endl;

}